package com.whmnx.main.ui.model;

import android.app.Application;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.tencent.qcloud.ugckit.utils.ToastUtil;
import com.whmnx.base.bean.GuaZhiBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.constants.EventConstants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.base.router.RouterActivityPath;
import com.whmnx.base.utils.UItils;
import com.whmnx.base.view.CustomPopWindow;
import com.whmnx.main.R;
import com.whmnx.main.databinding.FragmentSetupRulesBinding;
import com.whmnx.main.ui.fragment.SetupRulesFragment;
import com.wx.wheelview.adapter.ArrayWheelAdapter;
import com.wx.wheelview.widget.WheelView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.bus.RxSubscriptions;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;

import static android.content.Context.INPUT_METHOD_SERVICE;

/**
 * author : huang
 * date   : 2020/9/27 0027 17:57
 * version: 1.0
 * @author Administrator
 */
public class SetUpModel extends ToolbarViewMainModel implements View.OnClickListener {

    private TextView tvStart;
    private TextView tvEnd;
    private boolean flag3;
    private boolean flag4;
    private boolean flag5;
    private String address_value;
    private String rule_lat;
    private String rule_lng;

    public SetUpModel(@NonNull Application application) {
        super(application);
    }

    private CustomPopWindow mPopupWindow;
    private SetupRulesFragment mFragment;
    private FragmentSetupRulesBinding mBinging;
    private boolean flag1,flag2;



    public ObservableField<String> edit_time  = new ObservableField<>("编辑");
    public ObservableField<String> edit_video  = new ObservableField<>("编辑");
    public ObservableField<String> edit_Red  = new ObservableField<>("编辑");
    public ObservableField<String> edit_phone  = new ObservableField<>("编辑");
    public ObservableField<String> edit_after  = new ObservableField<>("编辑");
    public ObservableField<String> time  = new ObservableField<>("");
    //结束时间
    public ObservableField<String> time2  = new ObservableField<>("");
    public ObservableField<String> Rule_PeopleNumber  = new ObservableField<>("");
    public ObservableField<String> Rule_GroupValidTime  = new ObservableField<>("");
    public ObservableField<String> Rule_CommodityNumber  = new ObservableField<>("");
    public ObservableField<String> rule_VideoValidTime  = new ObservableField<>("");
    public ObservableField<String> rule_RedMoney  = new ObservableField<>("");
    public ObservableField<String> rule_RedStartTime  = new ObservableField<>("");
    public ObservableField<String> rule_RedNumber  = new ObservableField<>("");
    public ObservableField<String> rule_ServicePhone  = new ObservableField<>("");
    public ObservableField<String> rule_AfterSaleName  = new ObservableField<>("");
    public ObservableField<String> rule_AfterSalePhone  = new ObservableField<>("");
    public ObservableField<String> rule_AreaAddress  = new ObservableField<>("");
    public ObservableField<String> rule_AreaAddressDesc  = new ObservableField<>("");

    private String typeName;

    private Disposable subscribe;
    private String string;


    public void initToolbar(SetupRulesFragment setupRulesFragment, FragmentSetupRulesBinding binding) {
        this.mFragment = setupRulesFragment;
        this.mBinging = binding;
        setTitleText("设置规则");
        initView();
        Map<String, Object> params = new HashMap<>();
        params.put("ItemCode","CTRS");

        HttpClient.get(mFragment.getActivity(), Constants.GETITEMVALUE, params,new CallBack<String>() {
            @Override
            public void onSuccess(String result) {
                Rule_PeopleNumber.set(result);
            }
        });


        Map<String, Object> params2 = new HashMap<>();
        params2.put("uId",SPUtils.getInstance().getString(Constants.USERID));
        HttpClient.get(mFragment.getActivity(), Constants.GETRULETOUSER, params2,new CallBack<GuaZhiBean>() {
            @Override
            public void onSuccess(GuaZhiBean result) {
                time.set(result.getRule_ActionStartTime());
                time2.set(result.getRule_ActionEndTime());
                Rule_GroupValidTime.set(result.getRule_GroupValidTime() + "");
                Rule_PeopleNumber.set(result.getRule_PeopleNumber() + "");
                Rule_CommodityNumber.set(result.getRule_CommodityNumber() + "");
                rule_VideoValidTime.set(result.getRule_VideoValidTime() + "");
                rule_RedMoney.set(result.getRule_RedMoney());
                rule_RedStartTime.set(result.getRule_RedStartTime());
                rule_RedNumber.set(result.getRule_RedNumber());
                rule_ServicePhone.set((String) result.getRule_ServicePhone());
                rule_AfterSaleName.set((String) result.getRule_AfterSaleName());
                rule_AfterSalePhone.set((String) result.getRule_AfterSalePhone());

                rule_AreaAddress.set(result.getRule_AfterSaleAddress());
                //详情地址
                rule_AreaAddressDesc.set(result.Rule_LabelDetail);
                rule_lat = result.getRule_Lat();
                rule_lng = result.getRule_Lng();

            }
        });
    }


    private void initView() {
        subscribe = RxBus.getDefault().toObservable(String.class)
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String object){
                        if (object.contains(EventConstants.MAP)){
                            string = object.split(",")[1];
                            rule_AreaAddress.set(string.split("-")[2]);
                        }
                    }
                });
        RxSubscriptions.add(subscribe);
    }


    //编辑时间
    public BindingCommand OnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (edit_time.get().equals("编辑")){
                edit_time.set("完成");
                flag1 = true;
            }else {
                flag1 = false;
            }

            if (!flag1) {
                if (edit_time.get().equals("完成")) {
                    if (TextUtils.isEmpty(time.get())) {
                        ToastUtils.showShort("请选择活动开始时间");
                        return;
                    }
                    if (TextUtils.isEmpty(time2.get())) {
                        ToastUtils.showShort("请选择活动结束时间");
                        return;
                    }
                    if (TextUtils.isEmpty(Rule_GroupValidTime.get())) {
                        ToastUtils.showShort("请输入有效时间");
                        return;
                    }
                    if (TextUtils.isEmpty(Rule_PeopleNumber.get())) {
                        ToastUtils.showShort("请输入成团人数");
                        return;
                    }
                    if (TextUtils.isEmpty(Rule_CommodityNumber.get())) {
                        ToastUtils.showShort("请输入每人限购数量");
                        return;
                    }

                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    try {
                        Date  mtime1 = sf.parse(time.get());
                        Date  mtime2 = sf.parse(time2.get());

                        if(mtime1.getTime() > mtime2.getTime()){
                            ToastUtil.toastShortMessage("开始日期不能晚于结束日期");
                            return;
                        }

                    } catch (ParseException e) {
                        e.printStackTrace();
                    }


                    Map<String, Object> params = new HashMap<>();
                    params.put("rule_ActionStartTime", time.get());
                    params.put("rule_UserInfoId", SPUtils.getInstance().getString(Constants.USERID));
                    params.put("Rule_ActionEndTime", time2.get());
                    params.put("Rule_GroupValidTime", Rule_GroupValidTime.get());
                    params.put("rule_PeopleNumber", Rule_PeopleNumber.get());
                    params.put("rule_CommodityNumber", Rule_CommodityNumber.get());

                 /*   params.put("rule_VideoValidTime", "");
                    params.put("rule_RedMoney", "");
                    params.put("rule_RedStartTime", "");
                    params.put("rule_RedEndTime", "");
                    params.put("rule_RedEndTime", "");

                    params.put("rule_RedNumber", "");
                    params.put("rule_ServicePhone", "");
                    params.put("rule_AfterSaleName", "");
                    params.put("rule_AfterSalePhone", "");
                    params.put("rule_AreaAddress", "");
                    params.put("rule_AreaAddressDesc", "");
                    params.put("rule_AfterSaleAddress", "");

                    params.put("type", 0);*/


                    HttpClient.post(mFragment.getActivity(), Constants.APP_ADDORUPDATE, params, new CallBack<String>() {
                        @Override
                        public void onSuccess(String result) {
                            edit_time.set("编辑");
                            ToastUtil.toastShortMessage("编辑成功");
                        }
                    });
                }
            }
        }
    });


    //活动结束时间
    public BindingCommand OnClickCommand10 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            typeName = "活动结束时间";
            showWordTime(2);
        }
    });

    private void showWordTime(int type) {
        hideInput2();
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(2020, 1, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2030, 1, 1);

        TimePickerView pvTime = new TimePickerBuilder(mFragment.getActivity(), new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                if (type == 1) {
                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        Date  mtime1 = sf.parse(UItils.getDayTime());
                        Date  mtime2 = sf.parse(UItils.getTime2(date));
                        if (mtime2.getTime() >= mtime1.getTime()){
                            time.set(UItils.getTime2(date));
                        }else {
                            ToastUtil.toastShortMessage("开始日期须大于今天日期");
                            return;
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                } else {
                    time2.set(UItils.getTime2(date));
                }
            }
        })
                .setType(new boolean[]{true, true, true, true, true, true})//默
                .setTitleText(typeName)
                .setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(0xffFF6767)//确定按钮文字颜色
                .setCancelColor(0xff999999)//取消按钮文字颜色
                .setTitleBgColor(0xffF4F4F4)//标题背景颜色 Night mode
                .setTitleSize(16)
                .setContentTextSize(14)//滚轮文字大小
                .setTextColorCenter(0xff333333)
                .isCyclic(true)//是否循环滚动
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(startDate, endDate)//起始终止年月日设定
                .setTextColorOut(0x999999)
                .setDividerColor(0xffEEEEEE)
                .setLabel("年", "月", "日", "时", "分", "秒")
                .setOutSideCancelable(true)//点击外部dismiss default true
                .isDialog(false)//是否显示为对话框样式
                .setLineSpacingMultiplier((float) 2.5) //设置item的高度
                .build();
        //注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.setDate(Calendar.getInstance());
        pvTime.show();
    }

    private void hideInput2() {
        InputMethodManager imm = (InputMethodManager) mFragment.getActivity().getSystemService(INPUT_METHOD_SERVICE);
        View v = mFragment.getActivity().getWindow().peekDecorView();
        if (null != v) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }


    //短视频有效期
    public BindingCommand OnClickCommand3 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (edit_video.get().equals("编辑")) {
                edit_video.set("完成");
                flag2 = true;
            }else {
                flag2 = false;
            }

            if (!flag2) {
                if (TextUtils.isEmpty(rule_VideoValidTime.get())) {
                    ToastUtils.showShort("请输入短视频橱窗有效期时间");
                    return;
                }


                Map<String, Object> params = new HashMap<>();
                params.put("rule_VideoValidTime", rule_VideoValidTime.get());
                params.put("rule_UserInfoId", SPUtils.getInstance().getString(Constants.USERID));
                HttpClient.post(mFragment.getActivity(), Constants.DUANSHIPINCHUCHUANGXIAOQI, params, new CallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        edit_video.set("编辑");
                        ToastUtil.toastShortMessage("编辑成功");
                    }
                });
            }
        }
    });

    //红包编辑
    public BindingCommand OnClickCommand4 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (edit_Red.get().equals("编辑")) {
                edit_Red.set("完成");
                flag3 = true;
            } else {
                flag3 = false;
            }

            if (!flag3) {
                if (TextUtils.isEmpty(rule_RedMoney.get())) {
                    ToastUtils.showShort("请输入红包金额");
                    return;
                }
                if (TextUtils.isEmpty(rule_RedStartTime.get())) {
                    ToastUtils.showShort("请选择有效时间");
                    return;
                }
                if (TextUtils.isEmpty(rule_RedNumber.get())) {
                    ToastUtils.showShort("请输入红包数量");
                    return;
                }


                Map<String, Object> params = new HashMap<>();
                params.put("rule_RedMoney", rule_RedMoney.get());
                params.put("rule_RedStartTime", rule_RedStartTime.get());
                params.put("rule_RedEndTime", rule_RedStartTime.get());
                params.put("rule_RedNumber", rule_RedNumber.get());
                params.put("rule_UserInfoId", SPUtils.getInstance().getString(Constants.USERID));

                HttpClient.post(mFragment.getActivity(), Constants.HONGBAOGUIZE, params, new CallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        edit_Red.set("编辑");
                        ToastUtil.toastShortMessage("编辑成功");
                    }
                });
            }
        }
    });


    //客服电话
    public BindingCommand OnClickCommand5 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            if (edit_phone.get().equals("编辑")) {
                edit_phone.set("完成");
                flag4 = true;
            } else {
                flag4 = false;
            }

            if (!flag4) {
                if (TextUtils.isEmpty(rule_ServicePhone.get())) {
                    ToastUtils.showShort("请输入客服电话");
                    return;
                }

                Map<String, Object> params = new HashMap<>();
                params.put("rule_UserInfoId", SPUtils.getInstance().getString(Constants.USERID));
                params.put("rule_ServicePhone", rule_ServicePhone.get());
                HttpClient.post(mFragment.getActivity(), Constants.KEFUDIANHUA, params, new CallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        edit_phone.set("编辑");
                        ToastUtil.toastShortMessage("编辑成功");
                    }
                });
            }
        }
    });
    //地址
    public BindingCommand OnClickCommand6 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (edit_after.get().equals("编辑")) {
                edit_after.set("完成");
                flag5 = true;
            } else {
                flag5 = false;
            }

            if (!flag5) {
                if (TextUtils.isEmpty(rule_AfterSaleName.get())) {
                    ToastUtils.showShort("请输入联系人");
                    return;
                }
                if (TextUtils.isEmpty(rule_AfterSalePhone.get())) {
                    ToastUtils.showShort("请输入联系电话");
                    return;
                }
         /*   if (TextUtils.isEmpty(rule_AreaAddress.get())){
                ToastUtils.showShort("请输入售后地址");
                return;
            }*/
                if (TextUtils.isEmpty(rule_AreaAddress.get())) {
                    ToastUtils.showShort("请选择售后详细地址");
                    return;
                }

                Map<String, Object> params = new HashMap<>();
                params.put("rule_UserInfoId", SPUtils.getInstance().getString(Constants.USERID));
                params.put("rule_AfterSaleName", rule_AfterSaleName.get());
                params.put("rule_AfterSalePhone", rule_AfterSalePhone.get());

                //  params.put("rule_AreaAddress",address_value);
                //  params.put("rule_AreaAddressDesc",rule_AreaAddress.get());
                params.put("rule_AfterSaleAddress", rule_AreaAddress.get());
                params.put("Rule_LabelDetail", rule_AreaAddressDesc.get());
                if (!TextUtils.isEmpty(string)){
                    params.put("rule_Lat", string.split("-")[0]);
                    params.put("rule_Lng", string.split("-")[1]);
                }else {
                    params.put("rule_Lat", rule_lat);
                    params.put("rule_Lng", rule_lng);
                }

                HttpClient.post(mFragment.getActivity(), Constants.SHOUHOUDIZHI, params, new CallBack<String>() { //String
                    @Override
                    public void onSuccess(String result) {
                        edit_after.set("编辑");
                        ToastUtil.toastShortMessage("编辑成功");
                        SPUtils.getInstance().put("rule_AfterSalePhone", rule_AfterSalePhone.get());
                        SPUtils.getInstance().put("rule_AreaAddress", rule_AreaAddress.get());
                        SPUtils.getInstance().put("rule_AfterSaleName", rule_AfterSaleName.get());
                        SPUtils.getInstance().put("rule_AreaAddressDesc", rule_AreaAddressDesc.get());
                    }
                });
            }
        }
    });
    //设置地址
    public BindingCommand OnClickCommand7 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            hideInput();
            ARouter.getInstance().build(RouterActivityPath.User.ADDRESS).navigation();
            //申明对象
         /*   CityPickerView mPicker = new CityPickerView();
            //预先加载仿iOS滚轮实现的全部数据（oncreate()中）
            mPicker.init(mFragment.getActivity());

            //配置
            CityConfig cityConfig = new CityConfig.Builder()
                    .title("选择城市")//标题
                    .titleTextSize(16)//标题文字大小
                    .titleTextColor("#585858")//标题文字颜  色
                    .titleBackgroundColor("#ffdddddd")//标题栏背景色
                    .confirTextColor("#ffe1163c")//确认按钮文字颜色
                    .confirmText("确定")//确认按钮文字
                    .confirmTextSize(14)//确认按钮文字大小
                    .cancelTextColor("#585858")//取消按钮文字颜色
                    .cancelText("取消")//取消按钮文字
                    .cancelTextSize(14)//取消按钮文字大小
                    .setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)//显示类，只显示省份一级，显示省市两级还是显示省市区三级
                    .showBackground(true)//是否显示半透明背景
                    .visibleItemsCount(7)//显示item的数量
                    .province("湖北省")//默认显示的省份
                    .city("武汉市")//默认显示省份下面的城市
                    .district("洪山区")//默认显示省市下面的区县数据
                    .provinceCyclic(true)//省份滚轮是否可以循环滚动
                    .cityCyclic(true)//城市滚轮是否可以循环滚动
                    .districtCyclic(true)//区县滚轮是否循环滚动
                    .setCustomItemLayout(R.layout.item_city)//自定义item的布局
                    .setCustomItemTextViewId(R.id.item_city_name_tv)//自定义item布局里面的textViewid
                    .drawShadows(false)//滚轮不显示模糊效果
                    .setLineHeigh(1)//中间横线的高度
                    .setLineColor("#ffe1163c")
                    .setShowGAT(true)//是否显示港澳台数据，默认不显示
                    .build();
            //添加配置
            mPicker.setConfig(cityConfig);
            //显示
            mPicker.showCityPicker();
            //监听选择点击事件及返回结果
            mPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
                @Override
                public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                    super.onSelected(province, city, district);
                    //为TextView赋值
                    rule_AreaAddress.set(province + "" + city + "" + district);
                    address_value = province.getId() + "," + city.getId() + "," + district.getId();
                }

                @Override
                public void onCancel() {
                    super.onCancel();
                }
            });*/
        }
    });

    private void hideInput() {
        InputMethodManager imm = (InputMethodManager) mFragment.getActivity().getSystemService(INPUT_METHOD_SERVICE);
        View v = mFragment.getActivity().getWindow().peekDecorView();
        if (null != v) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }

    //设置时间
    public BindingCommand OnClickCommand2 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
          // getTime();
            typeName = "活动开始时间";
            showWordTime(1);
        }
    });

    //开始时间 和 结束时间
    private void getTime() {
        int popWindowWidth = (int) (UItils.getDeviceDensity(mFragment.getActivity()).widthPixels);
        int popWindowHeight = (int) (UItils.getDeviceDensity(mFragment.getActivity()).heightPixels);
        View contentView = LayoutInflater.from(mFragment.getActivity()).inflate(R.layout.popwindow_time, null);
        mPopupWindow = new CustomPopWindow.PopupWindowBuilder(mFragment.getActivity())
                .setView(contentView)
                .size(popWindowWidth, LinearLayout.LayoutParams.WRAP_CONTENT)
                .setFocusable(true)
                .setOutsideTouchable(true)
                .enableBackgroundDark(false)
                .setBgDarkAlpha((float) 1)
                .setAnimationStyle(R.style.BottomDialogAnimation)
                .create();
        mPopupWindow.showAtLocation(contentView, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0,0);


        contentView.findViewById(R.id.btnCancel).setOnClickListener(this);
        contentView.findViewById(R.id.btnSubmit).setOnClickListener(this);
        contentView.findViewById(R.id.tv_start).setOnClickListener(this);
        contentView.findViewById(R.id.tv_end).setOnClickListener(this);
        TextView tvTime = contentView.findViewById(R.id.tv_time);
        tvStart = contentView.findViewById(R.id.tv_start);
        tvEnd = contentView.findViewById(R.id.tv_end);


        WheelView hourWheelView = contentView.findViewById(R.id.year);
        hourWheelView.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        hourWheelView.setSkin(WheelView.Skin.Holo);
        hourWheelView.setWheelData(createYear());
        WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
        style.selectedTextColor = Color.parseColor("#FF2041");
        style.textColor = Color.GRAY;
        style.selectedTextSize = 20;
        hourWheelView.setStyle(style);
        hourWheelView.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        hourWheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String year = (String) o;
                tvTime.setText(year);
            }
        });


        WheelView minuteWheelView = contentView.findViewById(R.id.month);
        minuteWheelView.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        minuteWheelView.setSkin(WheelView.Skin.Holo);
        minuteWheelView.setWheelData(createMonth());
        minuteWheelView.setStyle(style);
        minuteWheelView.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        minuteWheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String month = (String) o;
                tvTime.setText(tvTime.getText().toString()  + "." + month);
            }
        });

        WheelView secondWheelView = contentView.findViewById(R.id.day);
        secondWheelView.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        secondWheelView.setSkin(WheelView.Skin.Holo);
        secondWheelView.setWheelData(createDay());
        secondWheelView.setStyle(style);
        secondWheelView.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        secondWheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String month = (String) o;
                tvTime.setText(tvTime.getText().toString() + "." + month);
            }
        });

        WheelView hourWheelView2 = contentView.findViewById(R.id.hour);
        hourWheelView2.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        hourWheelView2.setSkin(WheelView.Skin.Holo);
        hourWheelView2.setWheelData(createHours());
        hourWheelView2.setStyle(style);
        hourWheelView2.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        hourWheelView2.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String month = (String) o;
                tvTime.setText(tvTime.getText().toString() + " " + month + ":");
            }
        });

        WheelView hourWheelView3 = contentView.findViewById(R.id.min);
        hourWheelView3.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        hourWheelView3.setSkin(WheelView.Skin.Holo);
        hourWheelView3.setWheelData(createMinutes());
        hourWheelView3.setStyle(style);
        hourWheelView3.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        hourWheelView3.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String month = (String) o;
                tvTime.setText(tvTime.getText().toString()  + month + ":");
            }
        });

        WheelView hourWheelView4 = contentView.findViewById(R.id.second);
        hourWheelView4.setWheelAdapter(new ArrayWheelAdapter(mFragment.getActivity()));
        hourWheelView4.setSkin(WheelView.Skin.Holo);
        hourWheelView4.setWheelData(createMinutes());
        hourWheelView4.setStyle(style);
        hourWheelView4.setExtraText("", Color.parseColor("#FF2041"), 20, 50);
        hourWheelView4.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String month = (String) o;
                tvTime.setText(tvTime.getText().toString() + month);
            }
        });
    }


    private ArrayList<String> createYear() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 2020; i < 2030; i++) {
            list.add(i + "");
        }
        return list;
    }

    private ArrayList<String> createMonth() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i < 13; i++) {
            list.add("" + i);
        }
        return list;
    }


    private ArrayList<String> createDay() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i < 32; i++) {
            list.add("" + i);
        }
        return list;
    }

    private ArrayList<String> createHours() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 25; i++) {
            if (i < 10) {
                list.add("0" + i);
            } else {
                list.add("" + i);
            }
        }
        return list;
    }

    private ArrayList<String> createMinutes() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i < 61; i++) {
            if (i < 10) {
                list.add("0" + i);
            } else {
                list.add("" + i);
            }
        }
        return list;
    }





    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btnCancel) {
            mPopupWindow.dissmiss();
        } else if (id == R.id.btnSubmit) {



        }else if (id == R.id.tv_start){
            tvStart.setTextColor(mFragment.getActivity().getResources().getColor(R.color.white));
            tvStart.setBackgroundResource(R.drawable.red_drawable_oval);
            tvEnd.setTextColor(mFragment.getActivity().getResources().getColor(R.color.textColor));
            tvEnd.setBackgroundResource(R.drawable.white_drawable_oval);
        }else if (id == R.id.tv_end){
            tvEnd.setTextColor(mFragment.getActivity().getResources().getColor(R.color.white));
            tvEnd.setBackgroundResource(R.drawable.red_drawable_oval);
            tvStart.setTextColor(mFragment.getActivity().getResources().getColor(R.color.textColor));
            tvStart.setBackgroundResource(R.drawable.white_drawable_oval);


        }
    }
}
